package de.urlaub.server.logging;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.apache.log4j.Logger;

public class LoggingInterceptor {
	private Logger logger = Logger.getLogger(LoggingInterceptor.class);

	@AroundInvoke
	public Object log(InvocationContext ctx) throws Exception {
		logger.info("Enter " + ctx.getMethod());
		long startTime = 0;
		try {
			startTime = System.currentTimeMillis();
			return ctx.proceed();
		} finally {
			logger.info("Method " + ctx.getMethod() + " executed in "
					+ (System.currentTimeMillis() - startTime) + "ms");
			logger.info("Exit " + ctx.getClass().getSimpleName()
					+ ctx.getMethod());
		}
	}
}
